<template>
  <div class="list" ref="listWrap">
    <div>
      <div class="area" ref="#">
        <div class="title border-bottom">当前城市</div>
        <div class="city-list">
          <div class="city-wrap">
            <div class="city">广州</div>
          </div>
        </div>
      </div>
      <div class="area">
        <div class="title border-bottom">热门城市</div>
        <div class="city-list">
          <div class="city-wrap">
            <div class="city" v-for="item of hotCities" :key="item.id">{{item.name}}</div>
          </div>
        </div>
      </div>
      <div class="area">
        <div class="container"
          v-for="(item, key) in cities"
          :key="key"
          :ref="key"
        >
          <div class="title border-bottom">{{key}}</div>
          <div class="item-list">
            <div class="item" v-for="subItem of item" :key="subItem.id">{{subItem.name}}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import BScroll from 'better-scroll'
export default {
  name: 'List',
  props: {
    cities: Object,
    hotCities: Array,
    letter: String
  },
  mounted () {
    this.scroll = new BScroll(this.$refs.listWrap)
  },
  watch: {
    letter () {
      if (this.letter && this.letter !== '#') {
        const element = this.$refs[this.letter][0]
        this.scroll.scrollToElement(element)
      } else {
        // 直接返回顶部
        this.scroll.scrollTo(0, 0)
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
@import '~styles/variables.styl'
.list {
  overflow hidden
  position absolute
  top 1.68rem
  left 0
  right 0
  bottom 0
  .area {
    background-color #f8f8f8
    .title {
      font-size 0.26rem
      // font-weight bold
      color $bgColor
      padding 0.1rem 0.2rem
    }
    .city-list {
      background-color #fff
      .city-wrap {
        padding 0.1rem 0.2rem 0.1rem 0.1rem
        overflow hidden
        .city {
          box-sizing border-box
          float left
          width 30%
          margin 0.1rem
          padding 0.1rem
          text-align center
          border 0.02rem solid $bgColor
          border-radius 0.05rem
          color $lightTextColor
          // color $bgColor
        }
      }
    }
    .item-list {
      background-color #fff
      .item {
        padding 0.2rem
        border-bottom 0.02rem solid #eee
      }
    }
  }
}
</style>
